package filter;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet Filter implementation class cacheFilter
 */
public class cacheFilter implements Filter {

    /**
     * Default constructor. 
     */
    public cacheFilter() {
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see Filter#destroy()
	 */
	public void destroy() {
		// TODO Auto-generated method stub
	}

	/**
	 * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
	 */
	public void doFilter(ServletRequest request, ServletResponse _response, FilterChain chain) throws IOException, ServletException {
		// TODO Auto-generated method stub
		   HttpServletResponse response = (HttpServletResponse) _response;
		    response.setDateHeader("Expires", 0); //prevents caching at the proxy server
		    response.setHeader("Cache-Control", "private, no-store, no-cache, must-revalidate, max-stale=0"); //HTTP 1.1
		    response.addHeader("Cache-Control", "post-check=0, pre-check=0"); //IE Specific
		    response.setHeader("Pragma","no-cache"); //HTTP 1.0
		// pass the request along the filter chain
		chain.doFilter(request, response);
	}

	/**
	 * @see Filter#init(FilterConfig)
	 */
	public void init(FilterConfig fConfig) throws ServletException {
		// TODO Auto-generated method stub
	}

}
